/*
 * @lc app=leetcode.cn id=1221 lang=typescript
 *
 * [1221] 分割平衡字符串
 */

// @lc code=start
// 贪婪统计
function balancedStringSplit(s: string): number {
    let stack = 0;
    let count = 0;
    for (let i = 0; i < s.length; i++) {
        const element = s[i];
        if (element === "R") {
            stack++;
        } else {
            stack--;
        }
        if (stack === 0) count++;
    }
    return count;
}
// @lc code=end
